﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;

namespace FamilyCompare
{
	internal class ResultPackerBase
	{
		internal ResultPackerBase()
		{
			this.childPackers = new ChildResultPackerDataStructure();
		}

		internal ResultPackerBase(int id, int addId, string name, string value)
		{
			this.UseId = id;
			this.AdditionalId = addId;
			this.UseName = name;
			this.NodeName = name;
			this.UseValue = value;
			this.childPackers = new ChildResultPackerDataStructure();
		}

		internal int ID
		{
			get
			{
				return this.UseId;
			}
		}

		internal int AddID
		{
			get
			{
				return this.AdditionalId;
			}
		}

		internal string NdName
		{
			get
			{
				return this.NodeName;
			}
		}

		internal string Name
		{
			get
			{
				return this.UseName;
			}
		}

		internal string Value
		{
			get
			{
				return this.UseValue;
			}
		}

		internal ChildResultPackerDataStructure ChildPackers
		{
			get
			{
				return this.childPackers;
			}
		}

		internal bool IfAdd
		{
			get
			{
				return this.IfAdded;
			}
		}

		internal void SetChildResultPackerDataStructure(ChildResultPackerDataStructure input)
		{
			this.childPackers = input;
		}

		internal List<ResultPackerBase> GetLstNodeAtLevel(int inputLevel)
		{
			List<ResultPackerBase> list = new List<ResultPackerBase>();
			if (inputLevel == 0)
			{
				list.Add(this);
			}
			else if (this.childPackers != null && this.childPackers.CountSum != 0)
			{
				foreach (KeyValuePair<int, List<ResultPackerBase>> keyValuePair in this.childPackers.ThisValue)
				{
					foreach (ResultPackerBase resultPackerBase in keyValuePair.Value)
					{
						list.AddRange(resultPackerBase.GetLstNodeAtLevel(inputLevel - 1));
					}
				}
			}
			return list;
		}

		public bool IfAllEquals(ResultPackerBase input)
		{
			if (!input.Equals(input))
			{
				return false;
			}
			if (this.childPackers.CountId != input.childPackers.CountId)
			{
				return false;
			}
			bool flag = true;
			for (int i = 0; i < this.ChildPackers.CountId; i++)
			{
				List<ResultPackerBase> list = this.childPackers.ThisValue[this.childPackers.ThisValue.Keys.ElementAt(i)];
				List<ResultPackerBase> list2 = input.childPackers.ThisValue[input.childPackers.ThisValue.Keys.ElementAt(i)];
				if (list.Count != list2.Count)
				{
					flag = (flag && false);
				}
				else
				{
					for (int j = 0; j < list.Count; j++)
					{
						ResultPackerBase resultPackerBase = list[j];
						ResultPackerBase resultPackerBase2 = list2[j];
						if (resultPackerBase.NdName != resultPackerBase2.NdName)
						{
							flag = (flag && false);
						}
						else
						{
							flag = (flag && resultPackerBase.IfAllEquals(resultPackerBase2));
						}
					}
				}
			}
			return flag;
		}

		public override bool Equals(object obj)
		{
			if (!(obj is ResultPackerBase) || obj == null)
			{
				return false;
			}
			ResultPackerBase resultPackerBase = obj as ResultPackerBase;
			return resultPackerBase.ID == this.ID && resultPackerBase.Name.Equals(this.Name);
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		internal static ResultPackerBase CreatANoneValueNode(ResultPackerBase input)
		{
			if (input == null)
			{
				return null;
			}
			ResultPackerBase resultPackerBase = new ResultPackerBase();
			resultPackerBase.UseId = input.ID;
			resultPackerBase.UseName = input.UseName;
			resultPackerBase.NodeName = "无";
			resultPackerBase.AdditionalId = input.AddID;
			resultPackerBase.UseValue = string.Empty;
			resultPackerBase.IfAdded = true;
			if (input.childPackers != null && input.ChildPackers.CountSum != 0)
			{
				Utility.CreatANoneValueNodeChildStructure(input);
			}
			if (input is ElementTypeResultPacker)
			{
				return ElementTypeResultPacker.MakeACloneNoneValue(input as ElementTypeResultPacker);
			}
			return resultPackerBase;
		}

		public void OrderChildPacker()
		{
			this.OrderChildePacker(this.childPackers);
		}

		private void OrderChildePacker(ChildResultPackerDataStructure subChildStructure)
		{
			if (subChildStructure != null && subChildStructure.CountSum > 0)
			{
				foreach (KeyValuePair<int, List<ResultPackerBase>> keyValuePair in subChildStructure.ThisValue)
				{
					foreach (ResultPackerBase resultPackerBase in keyValuePair.Value)
					{
						resultPackerBase.ChildPackers.Order();
						this.OrderChildePacker(resultPackerBase.ChildPackers);
					}
				}
			}
		}

		protected string NodeName;

		protected int UseId;

		protected int AdditionalId;

		protected string UseName;

		protected string UseValue;

		protected Element thisElment;

		protected bool IfAdded;

		protected ResultPackerBase parerentPacker;

		protected ChildResultPackerDataStructure childPackers;
	}
}
